package com.sunxiansheng.user.service.impl;

import com.sunxiansheng.user.convert.SysUserConvert;
import com.sunxiansheng.user.entity.dto.SysUserDto;
import com.sunxiansheng.user.entity.page.PageResult;
import com.sunxiansheng.user.entity.page.SunPageHelper;
import com.sunxiansheng.user.entity.po.SysUserPo;
import com.sunxiansheng.user.entity.vo.SysUserVo;
import com.sunxiansheng.user.mapper.SysUserMapper;
import com.sunxiansheng.user.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (SysUser)service实现类
 *
 * @author sun
 * @since 2024-07-18 16:59:16
 */
@Service("Service")
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserMapper Mapper;

    /**
     * 分页查询
     *
     * @param Dto 筛选条件，需要携带pageNo和pageSize以及查询条件
     * @return 分页结果
     */
    @Override
    public PageResult<SysUserVo> queryByPage(SysUserDto Dto) {
        // 将dto转换为po
        SysUserPo Po = SysUserConvert.INSTANCE.convertDtoToPo(Dto);
        // 使用 SunPageHelper 执行分页操作
        PageResult<SysUserPo> paginate = SunPageHelper.paginate(Dto.getPageNo(), Dto.getPageSize(),
                () -> Mapper.count(Po),
                (offset, size) -> Mapper.queryPage(Po, offset, size)
        );
        // 将po转换为vo
        PageResult<SysUserVo> VoPageResult = SysUserConvert.INSTANCE.convertPageResult(paginate);
        return VoPageResult;
    }

}
